<template>
  <div class="IndexConfiguration">
    <div class="pubBig Privilege">
      <div class="h0">
        <p class="lt"></p>
      </div>
      <div class="dUpMain">

      </div>
      <div class="dDownMain">
        <div
          class="twoBox"
          :style="this.$route.query.Token ? 'top:50px;left:10px':'top: 100px'"
        >
          <el-row style="margin:10px;height:100px">
            <el-col :span="12">
              <span>相同分数：</span>
              <el-input
                size="mini"
                v-model="Same_score"
                style="display: inline-block;width:15%;margin-right:5px"
              ></el-input>
              <span style="color:red">高于或等于此分数即判断为相同患者</span>
            </el-col>
            <el-col :span="12">
              <span>相似分数：</span>
              <el-input
                size="mini"
                v-model="Similarity_score"
                style="display: inline-block;width:15%;margin-right:5px"
              ></el-input>
              <span style="color:red">高于或等于此分数且低于相同分数即判断为相似患者，低于此分数为不同患者</span>
            </el-col>
          </el-row>
          <el-row style="margin:10px">
            <el-col :span="24">
              <div style="margin-bottom:5px;float:left">
                <span>匹配字段配置 &nbsp 已权重 <span style="color:red">{{sumNow}}</span>
                  剩余
                  {{sum}}</span>
              </div>
              <template>
                <el-table
                  :data="tableData"
                  style="width: 100%"
                  ref="multipleTable"
                  :show-header="false"
                  @selection-change="handleSelectionChange"
                  :row-key="getRowKeys"
                  v-loading="isloading"
                  @select="handleSelectionChange_item"
                >
                  <el-table-column
                    type="selection"
                    width="55"
                    :reserve-selection="true"
                  >
                  </el-table-column>
                  <el-table-column prop="a">
                  </el-table-column>
                  <el-table-column prop="b">
                    <template slot-scope="scope">
                      {{scope.row.b}}
                      <el-input
                        type="num"
                        style="display: inline-block;width:50%"
                        size="mini"
                        v-model="scope.row.val_a"
                        @input="num_change(scope.row)"
                      ></el-input>
                    </template>
                  </el-table-column>
                  <el-table-column prop="c">
                    <template slot-scope="scope">
                      {{scope.row.c}}
                      <el-select
                        v-model="scope.row.val_b"
                        placeholder="请选择"
                        size="mini"
                      >
                        <el-option
                          v-for="item in options"
                          :key="item.value"
                          :label="item.label"
                          :value="item.value"
                        >
                        </el-option>
                      </el-select>
                    </template>
                  </el-table-column>
                </el-table>
              </template>
            </el-col>
          </el-row>
          <div style="width:100%;text-align: center;margin-top:15px">
            <el-button
              size="small"
              @click="editData"
            >保存</el-button>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "",
  data () {
    return {
      Same_score: '', // 相同分数
      Similarity_score: '', // 相似分数
      sumNow: 100,
      sum: 0,
      tableData: [],
      options: [{
        value: 1,
        label: '全匹配'
      }
        // , {
        //   value: 2,
        //   label: '重合度2/3匹配'
        // }
      ],
      multipleSelection: [],
      isloading: false,
      id: ''

    };
  },
  methods: {
    getTabledata () {
      this.isloading = true
      this.$get("/Patient/ThresholdInfo").then(res => {
        if (res.code == 0) {
          console.log(res);
          this.Same_score = res.data.SameScore
          this.Similarity_score = res.data.LikeScore
          var newList = res.data
          this.id = res.data.Id
          this.tableData = [
            {
              a: '证件号码',
              b: '字段权重',
              c: '匹配方法',
              val_a: newList.CardWeight,
              val_b: newList.CardMate,
              check: newList.IsCardNo
            },
            {
              a: '出生日期',
              b: '字段权重',
              c: '匹配方法',
              val_a: newList.BornWeight,
              val_b: newList.BornMate,
              check: newList.IsBorn
            }, {
              a: '联系电话',
              b: '字段权重',
              c: '匹配方法',
              val_a: newList.TelWeight,
              val_b: newList.TelMate,
              check: newList.IsTelphone
            }, {
              a: '患者姓名',
              b: '字段权重',
              c: '匹配方法',
              val_a: newList.NameWeight,
              val_b: newList.NameMate,
              check: newList.IsName
            }, {
              a: '性别名称',
              b: '字段权重',
              c: '匹配方法',
              val_a: newList.GenderWeight,
              val_b: newList.GenderMate,
              check: newList.IsGender
            }, {
              a: '联系人姓名',
              b: '字段权重',
              c: '匹配方法',
              val_a: newList.CnWeight,
              val_b: newList.CnMate,
              check: newList.IsContactName
            }, {
              a: '现住地址',
              b: '字段权重',
              c: '匹配方法',
              val_a: newList.AddressWeight,
              val_b: newList.AddressMate,
              check: newList.IsAddress
            },
            // {
            //   a: '联系人电话',
            //   b: '字段权重',
            //   c: '匹配方法',
            //   val_a: newList.CtWeight,
            //   val_b: newList.CtMate,
            //   check: newList.IsContactTel
            // },
            {
              a: '联系人证件号码',
              b: '字段权重',
              c: '匹配方法',
              val_a: newList.CcWeight,
              val_b: newList.CcMate,
              check: newList.IsContactCard
            }
          ]
          for (let i = 0; i < this.tableData.length; i++) {
            if (this.tableData[i].check == 1) {
              //这是默认选中上的
              this.$refs.multipleTable.toggleRowSelection(this.tableData[i], true);
            }
          }
          this.num_change()
          this.isloading = false
        }
      })
    },
    handleSelectionChange (val) {
      this.multipleSelection = val;
      for (var i = 0; i < this.multipleSelection.length; i++) {
        this.multipleSelection[i].containSpace = 1;
      }
    },
    getRowKeys (row) {
      return row.staffTypeId;
    },
    num_change (row) {
      let a = 0
      let b = this.tableData
      for (var i in b) {
        a = Number(b[i].val_a) + a
      }
      if (a > 100) {
        this.sumNow = a - row.val_a
        this.sum = 100 - (a - row.val_a)
        row.val_a = 0
        this.$message({
          message: '超出最大范围',
          type: 'warning'
        });
      } else {
        this.sumNow = a
        this.sum = 100 - a
      }
    },
    handleSelectionChange_item (selection, row) {
      if (row.check == 0) {
        row.check = 1
      } else if (row.check == 1) {
        row.check = 0
      }
    },
    editData () {
      let body = {
        Id: this.id,
        SameScore: this.Same_score,
        LikeScore: this.Similarity_score,
        IsCardNo: this.tableData[0].check,
        CardWeight: this.tableData[0].val_a,
        CardMate: this.tableData[0].val_b,
        IsBorn: this.tableData[1].check,
        BornWeight: this.tableData[1].val_a,
        BornMate: this.tableData[1].val_b,
        IsTelphone: this.tableData[2].check,
        TelWeight: this.tableData[2].val_a,
        TelMate: this.tableData[2].val_b,
        IsName: this.tableData[3].check,
        NameWeight: this.tableData[3].val_a,
        NameMate: this.tableData[3].val_b,
        IsGender: this.tableData[4].check,
        GenderWeight: this.tableData[4].val_a,
        GenderMate: this.tableData[4].val_b,
        IsContactName: this.tableData[5].check,
        CnWeight: this.tableData[5].val_a,
        CnMate: this.tableData[5].val_b,
        IsAddress: this.tableData[6].check,
        AddressWeight: this.tableData[6].val_a,
        AddressMate: this.tableData[6].val_b,
        // IsContactTel: this.tableData[7].check,
        // CtWeight: this.tableData[7].val_a,
        // CtMate: this.tableData[7].val_b,
        IsContactCard: this.tableData[7].check,
        CcWeight: this.tableData[7].val_a,
        CcMate: this.tableData[7].val_b,
      }
      console.log(body);
      this.$post("/Patient/ThresholdUpdate", body).then(res => {
        if (res.code == 0) {
          this.$message({
            message: '修改成功',
            type: 'success'
          });
        }
      })
    }
  },
  mounted () {
    // document.getElementById("2").focus();
  },
  created () {
    if (this.$route.query.Token) {
      localStorage.setItem('Token', this.$route.query.Token)
    }
    this.getTabledata()
  }
};
</script>
<style lang="scss">
.IndexConfiguration {
  .top-input {
    display: inline-block;
    width: 350px;
  }

  .box-top {
    margin-top: 15px;
    margin-left: 5px;
  }
  .input_style {
    display: inline-block;
    width: 15%;
  }
  .row_style {
    padding: 5px 0;
    border: 1px solid #eee;
  }
}
</style>
